package view;

import javafx.event.ActionEvent;
import javafx.event.Event;
import javafx.event.EventHandler;
import javafx.geometry.Insets;
import javafx.scene.control.Button;
import javafx.scene.control.TextField;
import javafx.scene.layout.FlowPane;
import javafx.scene.layout.Pane;
import javafx.scene.text.Font;
import javafx.scene.text.FontPosture;
import javafx.scene.text.FontWeight;

public class CenterPane extends FlowPane {
	private TextField textField = null;
	private int width = 52;
	private int height = 40;
	private int gaph = 4;
	private String out="";
	
	CenterPane(){
		super();
		
	}
	CenterPane(TextField textField){
		super();
		this.setStyle("-fx-background-color:#d3d7d4");
		this.setPadding(new Insets(2,4,2,4));
		this.setVgap(gaph);
		this.setHgap(gaph);

		FlowPane pane1 = new FlowPane();
//		pane1.setStyle("-fx-background-color:green");
		pane1.setPadding(new Insets(0,0,0,0));
		pane1.setPrefSize(5*width+4*gaph, 4*height+3*gaph);
		pane1.setVgap(gaph);
		pane1.setHgap(gaph);
		
		FlowPane pane2 = new FlowPane();
//		pane2.setStyle("-fx-background-color:black");
		pane2.setPadding(new Insets(0,0,0,0));
		pane2.setPrefSize(4*width+3*gaph, 2*height);
		pane2.setVgap(gaph);
		pane2.setHgap(gaph);
		
		FlowPane pane3 = new FlowPane();
//		pane3.setStyle("-fx-background-color:blue");
		pane3.setPadding(new Insets(0,0,0,0));
		pane3.setPrefSize(width, 2*height);
		pane3.setVgap(gaph);
		pane3.setHgap(gaph);
		
		this.getChildren().add(pane1);
		this.getChildren().add(pane2);
		this.getChildren().add(pane3);
		
		Button b1 = setButton(pane1, "MC", width, height, 20, "#fedcbd");
		b1.setOnAction(e->{
			
		});
		Button b2 = setButton(pane1, "MR", width, height, 20, "#fedcbd");
		Button b3 = setButton(pane1, "MS", width, height, 20, "#fedcbd");
		Button b4 = setButton(pane1, "M+", width, height, 20, "#fedcbd");
		Button b5 = setButton(pane1, "M-", width, height, 20, "#fedcbd");
		Button b6 = setButton(pane1, "←", width, height, 20, "#fedcbd");
		Button b7 = setButton(pane1, "CE", width, height, 20, "#fedcbd");
		Button b8 = setButton(pane1, "C", width, height, 20, "#fedcbd");
		Button b9 = setButton(pane1, "√▔", width, height, 20, "#fedcbd");
		Button b10 = setButton(pane1, "±", width, height, 20, "#fedcbd");
		Button b11 = setButton(pane1, "7", width, height, 20, "white");
		Button b12 = setButton(pane1, "8", width, height, 20, "white");
		Button b13 = setButton(pane1, "9", width, height, 20, "white");
		Button b14 = setButton(pane1, "÷", width, height, 20, "#fedcbd");
		Button b15 = setButton(pane1, "%", width, height, 20, "#fedcbd");
		Button b16 = setButton(pane1, "4", width, height, 20, "white");
		Button b17 = setButton(pane1, "5", width, height, 20, "white");
		Button b18 = setButton(pane1, "6", width, height, 20, "white");
		Button b19 = setButton(pane1, "×", width, height, 20, "#fedcbd");
		Button b20 = setButton(pane1, "1/x", width, height, 20, "#fedcbd");
		Button b21 = setButton(pane2, "1", width, height, 20, "white");
		Button b22 = setButton(pane2, "2", width, height, 20, "white");
		Button b23 = setButton(pane2, "3", width, height, 20, "white");
		Button b24 = setButton(pane2, "-", width, height, 20, "#fedcbd");
		Button b25 = setButton(pane2, ".", width, height, 20, "#fedcbd");
		Button b26 = setButton(pane2, "0", width, height, 20, "white");
		Button b27 = setButton(pane2, "+", 2*width+gaph, height, 20, "#fedcbd");
		Button b28 = setButton(pane3, "=", width, 2*height+gaph, 20, "#fedcbd");
		number(b11,textField);
		number(b12,textField);
		number(b13,textField);
		number(b14,textField);
		number(b15,textField);
		number(b16,textField);
		number(b17,textField);
		number(b18,textField);
		number(b19,textField);
		number(b21,textField);
		number(b22,textField);
		number(b23,textField);
		number(b24,textField);
		number(b25,textField);
		number(b26,textField);
		number(b27,textField);
	}
	public Button setButton(Pane pane, String name, int width,int height,int size,String color) {
		Button bt = new Button(name);
		bt.setPrefSize(width, height);
		bt.setPadding(new Insets(0,0,0,0));
		bt.setFont(Font.font("Times New Roman", FontWeight.BOLD, FontPosture.REGULAR, size));
		bt.setStyle("-fx-background-color:"+color);
		pane.getChildren().add(bt);
		return bt;
	}
	
	public void number(Button bt,TextField textField) {
		bt.setOnAction(e->{
			String number = bt.getText();
			out += number;
			textField.setText(out);
		});
	}
}
